//
//  BannerListModel.m
//
//  Created by  殷聃 on 2019/8/18
//  Copyright (c) 2019 yek. All rights reserved.
//

#import "BannerListModel.h"


NSString *const kBannerListModelId = @"id";
NSString *const kBannerListModelIsDelete = @"isDelete";
NSString *const kBannerListModelBannerHref = @"bannerHref";
NSString *const kBannerListModelAddTime = @"addTime";
NSString *const kBannerListModelBannerTitle = @"bannerTitle";
NSString *const kBannerListModelBannerType = @"bannerType";
NSString *const kBannerListModelBannerImg = @"bannerImg";
NSString *const kBannerListModelAddUser = @"addUser";


@interface BannerListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation BannerListModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize isDelete = _isDelete;
@synthesize bannerHref = _bannerHref;
@synthesize addTime = _addTime;
@synthesize bannerTitle = _bannerTitle;
@synthesize bannerType = _bannerType;
@synthesize bannerImg = _bannerImg;
@synthesize addUser = _addUser;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kBannerListModelId fromDictionary:dict] doubleValue];
            self.isDelete = [[self objectOrNilForKey:kBannerListModelIsDelete fromDictionary:dict] boolValue];
            self.bannerHref = [self objectOrNilForKey:kBannerListModelBannerHref fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kBannerListModelAddTime fromDictionary:dict] doubleValue];
            self.bannerTitle = [self objectOrNilForKey:kBannerListModelBannerTitle fromDictionary:dict];
            self.bannerType = [self objectOrNilForKey:kBannerListModelBannerType fromDictionary:dict];
            self.bannerImg = [self objectOrNilForKey:kBannerListModelBannerImg fromDictionary:dict];
            self.addUser = [self objectOrNilForKey:kBannerListModelAddUser fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kBannerListModelId];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kBannerListModelIsDelete];
    [mutableDict setValue:self.bannerHref forKey:kBannerListModelBannerHref];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kBannerListModelAddTime];
    [mutableDict setValue:self.bannerTitle forKey:kBannerListModelBannerTitle];
    [mutableDict setValue:self.bannerType forKey:kBannerListModelBannerType];
    [mutableDict setValue:self.bannerImg forKey:kBannerListModelBannerImg];
    [mutableDict setValue:self.addUser forKey:kBannerListModelAddUser];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kBannerListModelId];
    self.isDelete = [aDecoder decodeBoolForKey:kBannerListModelIsDelete];
    self.bannerHref = [aDecoder decodeObjectForKey:kBannerListModelBannerHref];
    self.addTime = [aDecoder decodeDoubleForKey:kBannerListModelAddTime];
    self.bannerTitle = [aDecoder decodeObjectForKey:kBannerListModelBannerTitle];
    self.bannerType = [aDecoder decodeObjectForKey:kBannerListModelBannerType];
    self.bannerImg = [aDecoder decodeObjectForKey:kBannerListModelBannerImg];
    self.addUser = [aDecoder decodeObjectForKey:kBannerListModelAddUser];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kBannerListModelId];
    [aCoder encodeBool:_isDelete forKey:kBannerListModelIsDelete];
    [aCoder encodeObject:_bannerHref forKey:kBannerListModelBannerHref];
    [aCoder encodeDouble:_addTime forKey:kBannerListModelAddTime];
    [aCoder encodeObject:_bannerTitle forKey:kBannerListModelBannerTitle];
    [aCoder encodeObject:_bannerType forKey:kBannerListModelBannerType];
    [aCoder encodeObject:_bannerImg forKey:kBannerListModelBannerImg];
    [aCoder encodeObject:_addUser forKey:kBannerListModelAddUser];
}

- (id)copyWithZone:(NSZone *)zone
{
    BannerListModel *copy = [[BannerListModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.isDelete = self.isDelete;
        copy.bannerHref = [self.bannerHref copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.bannerTitle = [self.bannerTitle copyWithZone:zone];
        copy.bannerType = [self.bannerType copyWithZone:zone];
        copy.bannerImg = [self.bannerImg copyWithZone:zone];
        copy.addUser = [self.addUser copyWithZone:zone];
    }
    
    return copy;
}


@end
